using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MapController : MonoBehaviour
{
	public GameObject WindowsStage;

	public GameObject WindowsStageHard;

	private int a;

	public GameObject[] MapLevel;

	public GameObject[] MapLevelHard;

	public GameObject HandTutorial;

	private GameObject abc;

	public GameObject Endless;

	public GameObject EndlessTong;

	public tk2dTextMesh texhMeshTotalCoin;

	public tk2dTextMesh texhMeshHealth;

	public tk2dTextMesh texhMeshHealthMax;

	public GameObject Hardtext;

	public GameObject Easytext;

	public GameObject MapHard;

	public GameObject MapEasy;

	public GameObject switchMap;

	private void OnEnable()
	{
		Social.ReportScore(GameManager.TotalCoin, "CgkI-erF35AMEAIQAQ", delegate
		{
		});
	}

	private void Start()
	{
		Time.timeScale = 1f;
		if (GameManager.key_stage > 10)
		{
			MapLevel[0].SetActive(value: true);
			switchMap.SetActive(value: true);
		}
		if (GameManager.key_stage > 20)
		{
			MapLevel[1].SetActive(value: true);
			EndlessTong.SetActive(value: true);
			Endless.transform.DORotate(new Vector3(0f, 0f, -360f), 2f, RotateMode.FastBeyond360).SetEase(Ease.Linear).SetLoops(-1);
		}
		if (GameManager.key_stage > 30)
		{
			MapLevel[2].SetActive(value: true);
		}
		if (GameManager.key_stage > 40)
		{
			MapLevel[3].SetActive(value: true);
		}
		if (GameManager.key_stage > 50)
		{
			MapLevel[4].SetActive(value: true);
		}
		if (GameManager.isHard)
		{
			MapHard.SetActive(value: true);
			check();
			MapEasy.SetActive(value: false);
			Easytext.SetActive(value: true);
			Hardtext.SetActive(value: false);
		}
		else
		{
			MapHard.SetActive(value: false);
			MapEasy.SetActive(value: true);
			Hardtext.SetActive(value: true);
			Easytext.SetActive(value: false);
		}
		if (GameManager.Tutorial == 0)
		{
			GameObject.Find("btn-select-map-1").GetComponent<Collider>().enabled = true;
			GameObject.Find("btn-go-shop").GetComponent<Collider>().enabled = false;
			GameObject.Find("btn-return-menu").GetComponent<Collider>().enabled = false;
			abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(2.5f, 3.5f, 0f), Quaternion.Euler(0f, 0f, 130f));
			abc.GetComponent<HandController>().Move(3.2f);
			GameManager.indexVukhi = 4;
		}
		if (GameManager.Tutorial == 1)
		{
			GameManager.indexVukhi = 0;
			GameObject.Find("btn-go-shop").GetComponent<Collider>().enabled = true;
			GameObject.Find("btn-select-map-1").GetComponent<Collider>().enabled = false;
			GameObject.Find("btn-return-menu").GetComponent<Collider>().enabled = false;
			abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(5f, -1f, 0f), Quaternion.Euler(0f, 0f, 130f));
			abc.GetComponent<HandController>().Move(-0.7f);
			GameManager.levelUpgrade[4] = -1;
		}
		if (GameManager.Tutorial == 2)
		{
			GameObject.Find("btn-select-map-1").GetComponent<Collider>().enabled = true;
			GameObject.Find("btn-go-shop").GetComponent<Collider>().enabled = false;
			GameObject.Find("btn-return-menu").GetComponent<Collider>().enabled = false;
			abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(2.5f, 3.5f, 0f), Quaternion.Euler(0f, 0f, 130f));
			abc.GetComponent<HandController>().Move(3.2f);
		}
		if (GameManager.Tutorial == 3 && GameManager.TotalCoin >= 9000)
		{
			GameObject.Find("btn-go-shop").GetComponent<Collider>().enabled = true;
			GameObject.Find("btn-select-map-1").GetComponent<Collider>().enabled = false;
			GameObject.Find("btn-return-menu").GetComponent<Collider>().enabled = false;
			abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(5f, -1f, 0f), Quaternion.Euler(0f, 0f, 130f));
			abc.GetComponent<HandController>().Move(-0.7f);
		}
	}

	private void Update()
	{
		texhMeshTotalCoin.text = GameManager.TotalCoin.ToString();
		texhMeshHealth.text = GameManager.numberHealth.ToString();
		texhMeshHealthMax.text = GameManager.numberBigHealth.ToString();
	}

	public void onClickMap(tk2dUIItem uiitem)
	{
		int index = uiitem.gameObject.GetComponent<SelectItem>().index;
		WindowsStage.SetActive(value: true);
		GameManager.map = index;
		if (GameManager.Tutorial == 0)
		{
			UnityEngine.Object.Destroy(abc);
			Invoke("HandHand", 1.3f);
		}
		if (GameManager.Tutorial == 2)
		{
			UnityEngine.Object.Destroy(abc);
			Invoke("HandHand1", 1.3f);
		}
	}

	public void onClickMapHard(tk2dUIItem uiitem)
	{
		int index = uiitem.gameObject.GetComponent<SelectItem>().index;
		WindowsStageHard.SetActive(value: true);
		GameManager.map = index;
	}

	private void HandHand()
	{
		abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(-2.65f, 2.05f, 0f), Quaternion.Euler(0f, 0f, 130f));
		abc.GetComponent<HandController>().Move(1.7f);
	}

	private void HandHand1()
	{
		abc = UnityEngine.Object.Instantiate(HandTutorial, new Vector3(-1.26f, 2.05f, 0f), Quaternion.Euler(0f, 0f, 130f));
		abc.GetComponent<HandController>().Move(1.7f);
	}

	public void onClickShop()
	{
		AudioController.Instance.SoundButtonAllGame();
		Invoke("LoadShop", 0.2f);
	}

	public void onClickMenu()
	{
		AudioController.Instance.SoundButtonAllGame();
		Invoke("LoadMenu", 0.2f);
	}

	public void onClickInGame(tk2dUIItem uiitem)
	{
		AudioController.Instance.SoundButtonAllGame();
		a = uiitem.gameObject.GetComponent<SelectItem>().index;
		GameManager.stage = a;
		SceneManager.LoadScene("Loading");
		if (GameManager.Tutorial == 2)
		{
			GameManager.Tutorial++;
		}
	}

	private void LoadShop()
	{
		SceneManager.LoadScene("shop");
	}

	private void LoadMenu()
	{
		SceneManager.LoadScene("Menu");
	}

	private void OnclickSwitchMap()
	{
		if (!GameManager.isHard)
		{
			MapHard.SetActive(value: true);
			MapEasy.SetActive(value: false);
			check();
			GameManager.isHard = true;
			Easytext.SetActive(value: true);
			Hardtext.SetActive(value: false);
		}
		else
		{
			MapHard.SetActive(value: false);
			MapEasy.SetActive(value: true);
			GameManager.isHard = false;
			Hardtext.SetActive(value: true);
			Easytext.SetActive(value: false);
		}
	}

	private void check()
	{
		if (GameManager.key_stageHard > 10)
		{
			MapLevelHard[0].SetActive(value: true);
		}
		if (GameManager.key_stageHard > 20)
		{
			MapLevelHard[1].SetActive(value: true);
		}
		if (GameManager.key_stageHard > 30)
		{
			MapLevelHard[2].SetActive(value: true);
		}
		if (GameManager.key_stageHard > 40)
		{
			MapLevelHard[3].SetActive(value: true);
		}
		if (GameManager.key_stageHard > 50)
		{
			MapLevelHard[4].SetActive(value: true);
		}
	}
}
